<template>
    <view>
        <view>
            <navbar title="历史考试"></navbar>
        </view>
        <!-- 考试列表 -->
        <view class="body">
            <template v-if="data.length!==0">
                <u-table>
                    <u-tr class="u-tr">
                        <u-th class="u-th">名称</u-th>
                        <u-th class="u-th">开始时间</u-th>
                        <u-th class="u-th">结束时间</u-th>
                        <u-th class="u-th">操作</u-th>
                    </u-tr>
                    <u-tr class="u-tr" v-for="exam in data">
                        <u-td class="u-td">{{exam.name}}</u-td>
                        <u-td class="u-td">{{new Date(exam.beginTime).toLocaleString()}}</u-td>
                        <u-td class="u-td">{{new Date(exam.endTime).toLocaleString()}}</u-td>
                        <u-td class="u-td"><u-button @click="toDetail(exam.id)">查看</u-button></u-td>
                    </u-tr>
                </u-table>
            </template>
            <template v-else>
                <u-empty></u-empty>
            </template>
        </view>

    </view>
</template>
<script>
    import {
        message,
        request
    } from '../../api'
    export default {
        data() {
            return {
                data: []
            }
        },
        async mounted() {
            const res = await request.get("/exam/history", {
                uid: uni.getStorageSync("uid")
            });
            console.log(res);
            if (res.code >= 0) {
                this.data = res.data
            }
        },
        methods: {
            toDetail(id) {
                uni.navigateTo({
                    url: "/pages/history/detail?id=" + id
                })
            }
        }
    }
</script>

<style>
    .body {
        height: calc(100vh - 3rem);
        overflow: auto
    }
</style>